<?php

$basedir = dirname(__FILE__);

require_once $basedir . '/../../../../extlib/Crypt/RSA.php';
require_once $basedir . '/../../../../extlib/Crypt/Random.php';
require_once $basedir . '/../../../../extlib/Crypt/Hash.php';
require_once $basedir . '/../../../../extlib/Math/BigInteger.php';

require_once $basedir . '/../../../../classes/magic.php';
require_once $basedir . '/../../../../classes/magic/signature/sign.php';

class Magic_Signature_SignTest extends PHPUnit_Framework_TestCase {
    
    private $encodedPrivateKey = "RSA.hkwS0EK5Mg1dpwA4shK5FNtHmo9F7sIP6gKJ5fyFWNotObbbckq4dk4dhldMKF42b2FPsci109MF7NsdNYQ0kXd3jNs9VLCHUujxiafVjhw06hFNWBmvptZud7KouRHz4Eq2sB-hM75MEn3IJElOquYzzUHi7Q2AMalJvIkG26c=.AQAB.JrT8YywoBoYVrRGCRcjhsWI2NBUBWfxy68aJilEK-f4ANPdALqPcoLSJC_RTTftBgz6v4pTv2zqiJY9NzuPo5mijN4jJWpCA-3HOr9w8Kf8uLwzMVzNJNWD_cCqS5XjWBwWTObeMexrZTgYqhymbfxxz6Nqxx352oPh4vycnXOk=";
    
    public function testConstructorOfMagicSignaturSignObject() {
        $object = new Magic_Signature_Sign($this->encodedPrivateKey);
        $this->assertEquals("Magic_Signature_Sign", get_class($object));
    }

    public function testSigningOfPayload() {
        
        $payload = '<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  <id>mimime:12345689</id>
  <title>Tuomas is now following Pamela Anderson</title>
  <content type="text/html">Tuomas is now following Pamela Anderson</content>
  <updated>2010-07-26T06:42:55+02:00</updated>
  <author>
    <uri>http://lobstermonster.org/tuomas</uri>
    <name>Tuomas Koski</name>
  </author>
  <activity:actor>
    <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
    <id>tuomas@lobstermonster.org</id>
    <title>Tuomas Koski</title>
    <link ref="alternate" type="text/html" href="http://identi.ca/tkoski"/>
  </activity:actor>
  <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
</entry>
';
        $object = new Magic_Signature_Sign($this->encodedPrivateKey);
        $signature = $object->sign(Magic::base64_url_encode($payload));
        $this->assertEquals("aMMmGLJd81bgBdU26WjVCT1zIH17ND0dlfArs1Kii_fVYFyz6IEyQzM3GddvzAfJ51vo-uN_RY9TEHtoHp12N9Abg9AbCcrPcBGvcP7VBhFWw857v_sYlbD6nek9cX9JKBu-C_Xf20QGuE5dPFL0S4kZsuemeQ8p6cJAj_RbumM=", $signature);
    }
}